﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class ChosePetItem : MonoBehaviour
    {
        public UILabel petName;
        public UILabel petLevel;
        public UILabel petAttribute;
        public GameObject petIconRoot;
        public GameObject checkBox;
        public delegate void OnGoBattle(string guid);
        public OnGoBattle m_callback;

        public delegate void OnCheckBoxChange(string guid, bool value);
        public OnCheckBoxChange m_OnCheckBox;

        public string petGuid;


        public GameObject goBattleBtn;


        public void SetPet(string guid, bool forSelect = false)
        {

            petGuid = guid;

            UIPet pet = StaticData.playerData.InstPlayerData.GetUIPet(guid);

            petIconRoot.transform.DestroyChildren();
            GameObject obj = AssetLoad.ResourceManager.Instance.LoadResource("prefab/PetIcon") as GameObject;
            GameObject icon = Instantiate(obj);
            icon.transform.parent = petIconRoot.transform;
            icon.transform.localPosition = new Vector3(0, 0, 0);
            icon.transform.localScale = new Vector3(1, 1, 1);
            icon.GetComponent<PetIcon>().SetPet(guid);
            Destroy(icon.GetComponent<BoxCollider>());

           // petLevel.text = TableTextBlo.GetText("level") + pet.level.ToString();
           // petName.text = pet.name;
            checkBox.SetActive(forSelect);
           // petAttribute.text = pet.name;

            goBattleBtn.SetActive(!forSelect);
        }

        // 上阵 获取
        public void OnGoBattleBtn()
        {
            if (m_callback != null)
            {
                m_callback(petGuid);
            }
        }

        public void OnCheckBox()
        {
            if (m_OnCheckBox != null)
            {
                m_OnCheckBox(petGuid, checkBox.GetComponent<UIToggle>().value);
            }
        }

        void OnClickIcon()
        {
            PageManager.Instance.OpenPage("UIPetPage", "petId=" + petGuid + "&showSwitchpet=false");
        }
    }
}


